function BasicModel_main() {
    var form = basicModel_form();
    return $.layout({
        id : 'basicModel_main_layout',
        items : [{
            dataChangeter : 'basicModelChangeter',
            style : $.border('Right'),
            region : 'west',
            width : 300,
            layout : 'fit',
            items : [{
                dataChangeter : 'basicModelChangeter',
                id : 'basicModel_main_jtreelist',
                xtype : 'jtreelist',
                order : ['modelSort->asc'],
                clazz : BasicModel,
                loadFn : function(treelist) {
                    if (!treelist.node) {
                        var node = treelist.getStore().getRoot(), selectNode = node.childNodes[0];
                        var sel = selectNode.childNodes[0] ? selectNode.childNodes[0] : selectNode;
                        treelist.setSelection(sel);
                        treelist.node = sel;
                        $('modelTitle').update($.nodeCase(treelist.getSelection(), ' > '));
                    } else {
                        var store = Ext.clone(treelist.getStore());
                        treelist.updateStore(store, treelist.old);
                        treelist.setSelection(store.getById(treelist.node.get('id')));
                    }
                },
                listeners : {
                    selectionchange : function(cmp, node) {
                        cmp.node = node;
                        $('modelTitle').update($.nodeCase(node, ' > '));
                        $.cmd({
                            type : 'load',
                            clazz : BasicModel,
                            fields : ['modelParentId.id'],
                            params : {
                                id : node.get('id')
                            },
                            callback : function(result) {
                                var data = result.data;
                                form.getForm().setValues(data);
                            }
                        })
                    }
                },
                mapper : 'id,modelName,modelParentId.id,modelSort,modelJs,modelMain,modelIcon,modelType'
            }]
        }, form.save({
            btnLeft : true,
            text : '保存模块信息',
            btnFn : function(form) {
                if (form.get('id').v() == 'index') {
                    return $.error('这个模块不能操作!');
                }
            },
            callback : function() {
                resetBasicModel();
            },
            notWin : true
        })]
    });
}

function basicModel_form() {
    return $({
        top : [{
            xtype : 'tbtext',
            id : 'modelTitle'
        }, '->', {
            cls : 'black',
            iconCls : 'fa-plus',
            text : '创建子模块',
            handler : function() {
                var select = $('basicModel_main_jtreelist').node;
                var form = $('basicModel_form');
                if (select) {
                    if (select.get('modelType') == '4') {
                        return $.error('按钮下无法加入模块');
                    }
                    form.getForm().reset();
                    form.set('modelParentId.id', select.get('id'));
                    $('modelTitle').update($.color('#E02222', '模块添加'));
                }
            }
        }],
        bbar : [{
            text : '删除当前模块',
            cls : 'red',
            iconCls : ion.del,
            handler : function() {
                var form = $('basicModel_form'), id = form.get('id').v();
                form.deletes({
                    validate : [[BasicModel, 'modelParentId.id', '名称为{modelName}的模块存在子模块,清除后才能删除.'],
                        [BasicRoleModel, 'modelId.id', '名称为{modelName}的模块存在角色关联,清除后才能删除'],
                        [BasicPortal, 'modelId.id', '名称为{modelName}的模块存在快捷方式关联,清除后才能删除']],
                    id : id,
                    callback : function(cmp, id, result) {
                        var tree = $('basicModel_main_jtreelist');
                        tree.node = tree.node.parentNode;
                        resetBasicModel();
                    }
                });
            }
        }],
        region : 'center',
        width : 400,
        clazz : BasicModel,
        id : 'basicModel_form',
        xtype : 'jform',
        validate : [['modelParentId.id = ?,modelName = ?', 'modelName', '同一上级模块下模块名称不能重复']],
        fields : [{
            xtype : 'fieldset',
            fieldsSize : 1,
            fields : [{
                req : true,
                text : '上级模块',
                xtype : 'jselecttree',
                name : 'modelParentId.id',
                tree : {
                    top : [$.treeSearch],
                    where : [['modelType', '!=', '4']],
                    clazz : BasicModel,
                    mapper : 'id,modelName,modelParentId.id,modelType,modelIcon'
                },
                listeners : {
                    change : function(field, newValue) {
                        var node = field.tree.getStore().getById(newValue), form = field.up('jform'), type = form.get('modelType'), js = form
                            .get('modelJs'), main = form.get('modelMain');
                        if (node) {
                            var modelType = node.get('modelType');
                            type.setValue({
                                '110' : '1',
                                '1' : '2',
                                '2' : '3',
                                '3' : '4'
                            }[modelType]);
                            // 模块
                            if (modelType == '2') {
                                js.show();
                                main.show();
                            } else {
                                js.hide();
                                main.hide();
                            }
                            var icon = form.get('modelIcon'), sort = form.get('modelSort');
                            // 按钮
                            if (modelType == '3') {
                                icon.setValue('fa-bolt');
                                main.show();
                                icon.hide();
                                sort.hide();
                            } else {
                                icon.show();
                                sort.show();
                            }
                        }
                    }
                }
            }, {
                name : 'modelType',
                readOnly : true,
                xtype : 'combo',
                maxLength : 30,
                store : $.dic('modelType'),
                req : true
            }, {
                maxLength : 120,
                name : 'modelName',
                req : true
            }, {
                maxLength : 120,
                name : 'modelMain',
                req : true
            }, {
                triggerCls : 'go-page',
                onTriggerClick : function() {
                    var url = "http://fortawesome.github.io/Font-Awesome/cheatsheet/";
                    window.open(url);
                },
                maxLength : 40,
                name : 'modelIcon'
            }, {
                minValue : 0,
                maxLength : 5,
                xtype : 'numberfield',
                name : 'modelSort'
            }, {
                name : 'modelJs',
                size : 1,
                req : true
            }]
        }]
    });
}

function resetBasicModel() {
    var cmp = $('basicModel_main_jtreelist');
    cmp.old = Ext.clone(cmp.getStore());
    cmp.getStore().load();
}